//
//  GGNavgationBar.m
//  GGProject
//
//  Created by yuemei on 2018/5/17.
//  Copyright © 2018年 yuemei. All rights reserved.
//

#import "GGNavgationBar.h"

@implementation GGNavgationBar

+ (instancetype)appearance{
   GGNavgationBar *bar = [super appearance];
   NSDictionary *textAttributesDic = @{
                                        NSForegroundColorAttributeName:HEXColor(0xffffff, 1),
                                        NSFontAttributeName:[UIFont systemFontOfSize:19]
                                        };
    [bar setTitleTextAttributes:textAttributesDic];
    bar.barStyle = UIBarStyleDefault;
    //设置导航条不透明
    bar.translucent = NO;
    
    //获取Navigation Bar的位置和大小
    [bar setBackgroundImage:[[DefaultTools sharedInstance] imageMakeWithRect:CGRectMake(0, 0, SCREEN_WIDTH, 64) Color:HEXColor(0x000000, 1)]
                forBarPosition:UIBarPositionAny
                    barMetrics:UIBarMetricsDefault];
    [bar setShadowImage:[UIImage new]];
    return bar;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    for (UIView *view in self.subviews) {
        if ([systemInfoTools currentDeviceVersion].doubleValue >= 11.0) {
            if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
                CGRect frame = view.frame;
                frame.size.height = 64;
                if ([systemInfoTools deviceType] == iPhoneX) {
                    frame.origin.y = 24;
                }
                view.frame = frame;
            }
            if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarContentView")]) {
                CGRect frame = view.frame;
                frame.origin.y = 20;
                if ([systemInfoTools deviceType] == iPhoneX) {
                    frame.origin.y = 44;
                }
                view.frame = frame;
            }
        }
    }
}

@end
